<%@page import="entities.Link"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.Category"%>
<%@page import="entities.User"%>
<%@page import="java.util.Map"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="java.util.List"%>
<%
User author = (User) request.getAttribute("author");
List<Link> links = (List<Link>) request.getAttribute("links"); 
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");
Category category = null;
LanguageHelper translate = (LanguageHelper) request.getAttribute("translate");
String success = (String) request.getAttribute("success");

//Paginator
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/user/layouts/header.jsp" />
<script type="text/javascript">
jQuery(document).ready(function () {
	jQuery("#profileTab li:eq(2)").addClass("active");
	jQuery(".remove").click(function () {
		var answer=confirm("Are you realy delete this artclie?");
		if(answer) {
			return true;
		}
		return false;
	});
});
</script>
                    <!-- change profile
					================================================== -->
                    <div class="tab-pane active" id="articles">
                    	<% if (success != null) { %>
			            <div class="alert alert-success"><%=success %></div>
			            <% } %>
                    
                        <table cellpadding="0" cellspacing="0" width="100%" class="table table-hover">
                        	<thead>
                            	<tr>
                                	<th>#</th>
                                    <th width="45%">Title</th>
                                    <th>Category</th>
                                    <th>Status</th>
                                    <th>Type</th>
                                    <th>&nbsp;</th>
                                </tr>
                            </thead>
                            <tbody>
                            	<% 
				                for (int i = 0; i < links.size(); i++) {
				                	category = categories.get(links.get(i).getCategory());
				                %>
                            	<tr>
                                	<td><%=i+1 %></td>
                                    <td><h5><%=links.get(i).getName() %></h5></td>
                                    <td><%=links.get(i).getCategory() %></td>
                                    <td>
                                    	<%
											switch (links.get(i).getStatus()) {
												case 0: 
													%>Inactive<%
													break;
												case 1:
													%>Pending<%
													break;
												case 2:
													%>Active<%
													break;
												default:
													break;
											}
											%>
                                    </td>
                                    <td><%=links.get(i).getType() %></td>
                                    <td>
                                    	<div class="btn-group">
                                            <a href="/profile/link/edit/<%=links.get(i).getId() %>/<%=links.get(i).getAuthKey() %>" class="btn btn-small"><i class="icon-edit"></i> Edit</a>
                                            <a href="/profile/link/delete/<%=links.get(i).getId() %>/<%=links.get(i).getAuthKey() %>" class="btn btn-small remove"><i class="icon-remove"></i> Remove</a>
                                        </div>
                                    </td>
                                </tr>
                                <% } %>
                            </tbody>
                        </table>
                        <!-- Pagination
       					================================================== -->
                        <div class="pagination pagination-right">
	                        <ul>
			                    <%
								List<Integer> range = paginator.getRangePage();
								%>
			                    <% if (prevPage) { %>
								<li><a href="<%=paginator.getPrev()%>"><%=translate.getString("prev")%></a></li>
								<% } %>
								<%
								if (nextPage || prevPage) {
									for (int i = 0; i < range.size(); i++) {
								%>
								<li><a class="<%=range.get(i).intValue() == pages ? "current" : "" %>" href="<%=range.get(i).intValue() == pages ? "javascript: return false;" : paginator.getPage(range.get(i).intValue())%>"> <%=range.get(i).toString() %> </a></li>
								<%  }
								} %>
								
								<% if (nextPage) { %>
								<li><a href="<%=paginator.getNext()%>"> <%=translate.getString("next")%> </a></li>
								<% } %>
			                </ul>
			            </div>
                    </div>
                    
                    
<jsp:include page="/user/layouts/footer.jsp" />